﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Security.Cryptography;
using ModeloGaleriaNET.Properties;

namespace ModeloGaleriaNET
{
    public class UserConnData
    {
        /// <summary>
        /// Nombre de usuario
        /// </summary>
        private String user;
        /// <summary>
        /// Contraseña
        /// </summary>
        private String password;
        
        /// <summary>
        /// El constructor es privado para garantizar que los usuarios no puedan crear instancias de la clase.
        /// </summary>
        private UserConnData()
        {
            this.user = Settings.Default.User;
            this.password = Utilities.DesencriptarRSA(Settings.Default.Pass);
        }

        /// <summary>
        /// Instancia singleton de la clase DBConnectionData
        /// </summary>
        public static readonly UserConnData Instance = new UserConnData();

        public String User
        {
            get { return user; }
            set { user = value; }
        }

        public String Password
        {
            get { return password; }
            set { password = value; }
        }

        public void Save()
        {
            Settings.Default.User = user;
            Settings.Default.Pass = Utilities.EncriptarRSA(this.password);
            Settings.Default.Save();
        }

        public void Clear()
        {
            user = string.Empty;
            password = string.Empty;
            Save();
        }

        public bool IsEmpty()
        {
            return string.IsNullOrWhiteSpace(user) ||
                   string.IsNullOrWhiteSpace(password);
        }
    }
}
